﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Documents;

namespace pklib.Manip {
	class Patterns {

		public static String ResolvePattern(String Input, String Pattern) {
			String[] Params = Pattern.Split('/');
			String	Output = Input;

			switch (Params[0]) {
				case "r":
					int Index = 0;
					Output = Params[2];
					foreach (Group match in Regex.Match(Input, Params[1]).Groups)
						Output = Output.Replace(String.Format("${0}", Index++), match.Value);
					break;
				case "s":
					Output = Output.Replace(Regex.Match(Input, Params[1]).Groups[0].Value, Params[2]);
					break;
				default:
					throw new Exception(String.Format("Command {0} not recognized by pklib.Patterns.ResolvePattern(\"{1}\", \"{2}\")", Params[0], Input, Pattern));
			}
			return Output;
		}
	}
}
